import RPi.GPIO as GPIO

class RaspGPIO:

    def __init__(self, pins, frequence):
        self.pins = {pin_id:None for pin_id in pins}
        self.frequence = frequence

    def start(self):
        GPIO.setmode(GPIO.BOARD)

        for pin_id in self.pins.keys():
            GPIO.setup(pin_id,GPIO.OUT)
            self.pins[pin_id] = GPIO.PWM(pin_id,self.frequence)
            self.pins[pin_id].start(0)

    def change(self,pin_id,dc):
        if self.pins[pin_id]:
            self.pins[pin_id].ChangeDutyCycle(dc)

    def stop(self):
        for pin_id in self.pins.keys():
            self.pins[pin_id].stop()

        GPIO.cleanup()